import { facade, get, middlewares, post, put } from "@atinc/chaos/facade";
import { UserService } from "./service";
import { inject } from "@atinc/chaos/container";
import { UserEntity } from "../../entity/user.entity";
import { CreateUserRequest, GetUserRequest, UpdateUserRequest } from "./request";
import { OperationContext, RouterContext } from "@atinc/chaos/router";
import { PagenationRequest } from "@atinc/chaos/repository/pagenation-calculator";
import { FindByPageIndexResult } from "@atinc/chaos/repository/find-by-page-index-result";

@facade()
@middlewares(
    async (ctx, next) => {
        console.log("facade middleware");
        return next();
    }
)
export class UserFacade {
    @inject()
    public userService!: UserService;

    @get("/user/all")
    public async users(ctx: RouterContext<OperationContext>): Promise<UserEntity[]> {
        return this.userService.getAllUsers(ctx);
    }

    @get("/users")
    public async pageUsers(ctx: RouterContext<OperationContext>, page: PagenationRequest): Promise<FindByPageIndexResult<UserEntity>> {
        return this.userService.getUsers(ctx, page);
    }

    @get("/user/:id")
    public async getUser(ctx: RouterContext<OperationContext>, request: GetUserRequest): Promise<Partial<UserEntity>> {
        return this.userService.getUser(ctx, request);
    }

    @post("/user",CreateUserRequest)
    public async createUser(ctx: RouterContext<OperationContext>, request: CreateUserRequest): Promise<UserEntity> {
        return this.userService.createUser(ctx, request);
    }

    @put("/delete")
    public async deleteUser(ctx: RouterContext<OperationContext>, request: CreateUserRequest): Promise<UserEntity> {
        return this.userService.createUser(ctx, request);
    }

    @put("/user")
    public async updateUser(ctx: RouterContext<OperationContext>, request: UpdateUserRequest): Promise<UserEntity> {
        return this.userService.updateUser(ctx, request);
    }

}

